//index.js
//获取应用实例
const app = getApp()
const mineService = require('../../service/mine.js');

Page({
  data: {
    title:"我的动态",
    list: [],
    queryParams: {
      page: 1,
      num: 10
    },
    isLast: false
  },
  onLoad: function () {
    this.getContentList();
  },
  getContentList() {
    let d = {
      ...this.data.queryParams,
      unionId: app.globalData.userinfo.unionId
    }
    mineService.getMineDynamic(d).then(res => {
      if (res.resCode == 0) {
        if (!res.object.length) {
          this.setData({
            isLast: true
          });
          return false;
        }
        this.setData({
          list: [
            ...this.data.list,
            ...res.object
          ]
        });
      }
    })
  },
  onReachBottom() {
    if (this.data.isLast) return false;
    this.setData({
      queryParams: {
        page: ++this.data.queryParams.page,
        num: 10
      }
    })
    this.getContentList();
  },
  // 0动态 1文章 2视频 3问答 4活动
  deleteRecord(e) {
    let detail = e.detail;
    let rowData = this.data.list[detail.index];
    let d = {
      objectId: rowData.circleId,
      type: 0
    }
    mineService.deleteContent(d).then(res => {
      if (res.resCode == 0) {
        wx.showToast({
          title: '删除成功',
          icon: 'success',
          duration: 1500
        });
        this.data.list.splice(detail.index, 1);
        this.setData({
          list: this.data.list
        });
      }
    })
  }
})
